package com.example.larouzey.adcproject;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.cbtService.AndroidSDK.ADCService;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    private EditText ed;
    private Button bt;
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            ed.setText(ADCService._adc_on()*(3.3/4096)+"V");
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ed=(EditText)findViewById(R.id.EditView);
        bt=(Button)findViewById(R.id.button);

        ed.setOnClickListener(this);
        bt.setOnClickListener(this);

        ADCService._init();

    }

    @Override
    public void onClick(View view) {
        switch(view.getId()){
            case R.id.button:
                Timer timer = new Timer();
                TimerTask timerTask=new TimerTask() {
                    @Override
                    public void run() {
                        handler.sendMessage(null);
                    }
                };
                timer.schedule(timerTask,0,3000);
                break;
        }
    }
}
